package com.sport.bean;

import com.google.gson.Gson;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * 列表分页、排序、搜索通用接收参数封装
 *
 * @Author wxq
 * @Date 2021/5/12
 **/

public class PageParam<T> {

    private Map<String, Object> pageData;

    public PageParam(HttpServletRequest request) {
        init(request);
    }

    public PageParam<T> init(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        Enumeration<String> names = request.getParameterNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            //判断是否为模糊查询
            if (name.equals("searchParams")) {
                String value = request.getParameter(name);
                Gson gson = new Gson();
                map = gson.fromJson(value, Map.class);

            }


        }
        setPageData(map);
        return this;
    }

    public Map<String, Object> getPageData() {
        return pageData;
    }

    public void setPageData(Map<String, Object> pageData) {
        this.pageData = pageData;
    }
}
